package test;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by Connor Madden.
 * User: Connor Madden
 * Date: 20/08/11
 * Time: 8:15 PM
 */

public class Timer extends Observable implements Runnable {
    int t;

    /**
     * The constructor setting the time <tt>t</tt> and adding the observer <tt>o</tt>
     *
     * @param t the time (milliseconds)
     * @param o the observer
     */
    public Timer(int t, Observer o) {
        this.t = t;
        addObserver(o);
    }

    /**
     * Pause for <tt>t</tt> milliseconds then notify observers
     */
    public void run() {
        setChanged();
        try {
            Thread.sleep(t);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        notifyObservers();
    }
}

